<template>
  <view class="page">
	<view class="images" v-for="(item,index) in images" :key="index">
		<image class="image" mode='scaleToFill' lazy-load="true" @click="preview(url+item.img_path_cos)" :src="url+item.img_path_cos+'?imageMogr2/thumbnail/!30p'"></image>
	</view>
  </view>
</template>
 
<script>
	
import md5 from "./md5.js";

export default {
  data() {
    return {
		share:{
			title:'气质美女免费壁纸',
			path:'/pages/index/index',
			imageUrl:'',
			desc:'',
			content:''
		},
		images:[],
		images_url:'',
		url:"https://img-1251827091.cos.ap-nanjing.myqcloud.com/"
    };
  },
  methods: {
	  preview(url){
		uni.previewImage({
			urls:[url]
		})
	  },
    get_images(){
		var that=this
		uni.showLoading({
			title:'正在加载...'
		})
		// 获取时间戳
		var timestamp=new Date().getTime()
		// 加密时间戳
		var timestamp_encode=md5.hex_md5(String(timestamp))
		// console.log(timestamp)
		uni.request({
			url:'https://img.tianxuanapp.com/api/index/list',
			data:{
				timestamp:timestamp,
				sign:timestamp_encode
			},
			success: res => {
				uni.stopPullDownRefresh()
				uni.hideLoading()
				if(res.data.code == 200){
					that.images = that.images.concat(res.data.data)
					that.share.imageUrl = that.url+res.data.data[0]['img_path_cos'];
					that.share.title = '气质美女免费壁纸';
					that.share.desc = that.share.content = that.url+res.data.data[0]['name'];
				}else{
					uni.showToast({
						title:'出错了...',
						icon:'none'
					})
				}
			},
			fail: () => {}
		});
	}
  },
  onLoad:function(){
  	// console.log(md5.hex_md5('1'))
	this.get_images()
  },
  onPullDownRefresh(){
	 this.images=[]
	 this.get_images()
  },
  onReachBottom(){
	  this.get_images()
  }
};
</script>
 
<style lang="less">
	.page{
		width: 710rpx;
		margin: 0 auto;
		display: flex;
		flex-direction: row;
		flex-wrap: wrap;
		justify-content: space-between;
	}
	.image{
		width: 710rpx;
		border-radius: 20rpx;
		margin-top: 10rpx;
		// height: 100rpx;
	}
</style>